package com.prs.crm.action;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.XJAction;

import com.prs.crm.context.AppContext;
import com.prs.crm.context.UserLoginStore;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.service.exchange.OnlinePersonService;

public class LogoutAction extends XJAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3127293903194114250L;
	private OnlinePersonService onlinePersonService; 
	public OnlinePersonService getOnlinePersonService() {
		return onlinePersonService;
	}
	public void setOnlinePersonService(OnlinePersonService onlinePersonService) {
		this.onlinePersonService = onlinePersonService;
	}
	@Action(value="logout",results={@Result(name="success",type="redirect",location="index")})
	public String logout()
	{
		if(AppContext.getAccountContext()==null){
			
		}else{
		Person account = AppContext.getAccountContext().getUser();
		UserLoginStore.removeUser(account);
		System.out.println(account);
		int i = this.getOnlinePersonService().removePerson(account);
		System.out.println(i);
		if(i>0){
			System.out.println("会话结束");
		}
		}
		
		ServletActionContext.getRequest().getSession().invalidate();
		return SUCCESS;
	}
}
